package com.easygem.system.service.impl;

import com.easygem.common.error.SystemCodeEnum;
import com.easygem.common.error.SystemException;
import com.easygem.system.service.UploadService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

/**
 * @Author 李伟
 * @Date 2022/8/19 14:59
 * @Version 1.0
 **/
@Service
public class UploadServiceImpl implements UploadService {

    @Override
    public String uploadImage(MultipartFile file) throws IOException, SystemException {
        if (file.isEmpty()) {
            throw new SystemException(SystemCodeEnum.PARAMETER_ERROR,"上传的文件不能为空");
        }
        InputStream inputStream = file.getInputStream();
        //文件的原名称
        long size = file.getSize();
        String originalFilename = file.getOriginalFilename();
        String fileExtName = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
        //保存图片信息到数据库
        BufferedImage image = ImageIO.read(file.getInputStream());

        //TODO  保存图片
        return  "";
    }


    @Override
    @Transactional
    public void delete(Long id) throws SystemException {
        //TODO  保存图片
    }
}
